local zhengyi = fk.CreateSkill {
  name = "zhengyi",
}

zhengyi:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes("js__lirang", Player.HistoryRound) > 0 and
      #player.room.logic:getEventsOfScope(GameEvent.Damage, 2, function (e)
        return e.data.to == player
      end, Player.HistoryTurn) == 1 and
      not player.room:getPlayerById(player:getMark("js__lirang-round")).dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(room:getPlayerById(player:getMark("js__lirang-round")), self.name, nil,
      "#zhengyi-invoke:"..player.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local new_data = table.simpleClone(data)
    new_data.to = room:getPlayerById(player:getMark("js__lirang-round"))
    room:damage(new_data)
    return true
  end,
})

return zhengyi